<%@page import="lib_model.Cart.ItemCart"%>
<%@page import="lib_model.Cart.Cart"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<% if (request.getSession().getAttribute("User") == null) {%>
<jsp:forward page="../auth/Logout"></jsp:forward>
<%}%>
<jsp:include page="../templates/Header.jsp"></jsp:include>
    Your Cart
<jsp:include page="../templates/Title.jsp"></jsp:include>
    <script type="text/javascript">
        $(document).ready(function(){
            $(".quantity").change(function(){
                $.ajax({
                    url: "../Cart/ChangeQuantityItemCart?quantity="+$(this).attr("value")+"&id="+ $(this).attr("productid"),
                    context: document.body,
                    success: function(){
                        alert("Change Quantity Finish !!!");
                        window.location = "";
                    }
                });
            });

            $("#checkout").click(function(){
                window.location = "../Cart/CheckOut";
            });
        });
    </script>
<jsp:include page="../templates/Style.jsp"></jsp:include>
    <div class="body-center w960">
        <h2 class="title-show">Your Cart</h2>
        <table class="tb">
            <thead>
                <tr>
                    <th align="left" width="20%">Name Product</th>
                    <th align="left" width="20%">Quantity</th>
                    <th align="left" widtue=""h="20%">Price</th>
                    <th align="left" widtue=""h="20%">Total Price</th>
                </tr>
            </thead>
            <tbody>
            <%
                Cart cart = null;
                cart = (Cart) request.getSession().getAttribute("Cart");
                if (cart == null) {
                    response.sendRedirect("home.jsp");
                    return;
                }
                for (ItemCart item : cart.getListCart()) {
            %>
            <tr>
                <td><%= item.product.name%></td>
                <td><input type="text" class="quantity" productid="<%= item.id%>"  value="<%= item.quantity%>"/></td>
                <td><%= item.product.price%> $</td>
                <td><%= item.getTotalPrice()%> $</td>
                <td width="50px"><a href="../Cart/RemoveItemCart?id=<%= item.id%>"><img src="../contents/icon/svn_deleted.png" border=0 /></a>
                </td>
            </tr>
            <%
                }
            %>
            <tr>
                <td>Total</td><td></td><td></td><td><%= cart.TotalCart()%> $</td><td><input type="button" value="Checkout" id="checkout"/></td>
            </tr>
        </tbody>
    </table>

</div>
<jsp:include page="../templates/Footer.jsp"></jsp:include>